#include "Unit.h"

Unit::Unit(int hp, UINT hBoxW, UINT hBoxH, int texture)
{
	HP = hp;
	MAXHP = hp;
	HitBoxW = hBoxW;
	HitBoxH = hBoxH;
	TextureId = texture;
	HealthBar = Sprite(5);
}

void Unit::UpdateHealthBar()
{
	if (!HealthBarLoaded && !HealthBar.flags)
	{
		HealthBar.scaleX = HitBoxW / HealthBar.Width;
		HealthBar.scaleY = 19.0f / (float)HealthBar.Height;
		HealthBarLoaded = true;
	}
	HealthBar.x = this->x;
	HealthBar.y = this->y - this->HitBoxH / 2 - 10;
	if (HealthBarLoaded) HealthBar.CropX = floor(((float)(MAXHP - HP) / (float)MAXHP) * HealthBar.Width + 0.5);
}